<template>
  <view class="container">
    <!-- scroll -->
    <swiper
      class="banner-swiper"
      circular
      autoplay
      indicator-dots
      indicator-color="#aaaaaa"
      indicator-active-color="#e4304d"
      :interval="5000"
      :duration="1000"
    >
      <swiper-item
        class="banner-swiper-item"
        v-for="(item, index) in pageData.AdvCar"
        :key="index"
      >
        <!-- 图片{{ index }} -->
        <image
          :src="
            item.FImgUrl.startsWith('http')
              ? item.FImgUrl
              : imageUrl + item.FImgUrl
          "
          mode="aspectFill"
          @tap="onPicClick(item)"
     />
      </swiper-item>
    </swiper>

    <!-- 积分兑换 -->
    <view class="jf">
      <view class="jf-h">
        <view class="jf-h-l"> 积分兑换</view>
        <view class="jf-h-r" @tap="onABC"> 全部商品 ></view>
      </view>
      <view class="jf-items">
        <view class="jf-item"> </view>
      </view>
    </view>
    
    <!-- 积分兑换  -->
    <scroll-view
      v-if="m_goodsList.length > 0"
      class="product-section"
      scroll-y
      scroll-with-animation
      @scrolltolower="onscrolltolower"
    >
      <view class="wrapper">
        <view class="products">
          <view
            class="product"
            v-for="(good, key) in m_goodsList"
            :key="key"
            @tap="goToDetail(good)"
          >
            <!-- imageUrl + -->
            <image :src="good.FProImage" mode="aspectFit" class="image" />
            <view class="content">
              <view class="name">{{ good.FName }}</view>
              <view class="price">
                <view>
                  <text class="symbol">{{ good.FMallPoint }}</text>
                  <text>积分</text>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>

    <li-tab-bar :curIdx="0" />
  </view>
</template>

<script>
import { reqPost } from "../../common/http.request";
import {
  uNavigateTo,
  uRedirectTo,
  uSetStorageSync,
  uSwitchTab,
  uToast,
} from "../../utils/uniUtils";

export default {
  data() {
    return {
      pageData: [],
      isLoaded: false,
      keyword: "",
      m_goodsList: [],
    };
  },
  async onShow() {
    try {
      /*       if (!uGetStorageSync("hasBindStore")) {
        // uToast("未绑定店铺~", "error");
        return;
      } */
      await this.getPageList();
      this.isLoaded = true;
    } catch (error) {
      console.log("error", error);
      this.isLoaded = false;
    }
  },

  methods: {
    async getPageList() {
      this.pageData = (await reqPost("GetHomeData")).Data;
    },
    onPicClick(item) {
      if (item.FGoodsID > 0) {
        uNavigateTo("/pages/goods/detail?id=" + item.FGoodsID);
      } else if (item.FGoodsClsID > 0) {
        uSetStorageSync("fl", item.FGoodsClsID);
        uSwitchTab("/pages/tab_bar/fl");
      }
    },
    onClassNav(item) {
      if (item.FGoodsID > 0) {
        uNavigateTo("/pages/goods/detail?id=" + item.FGoodsID);
      } else if (item.FGoodsClsID > 0) {
        uSetStorageSync("fl", item.FGoodsClsID);
        uSwitchTab("/pages/tab_bar/fl");
      }
    },
    search() {
      /*  if (!uGetStorageSync("hasBindStore")) {
        uToast("未绑定店铺~", "error");
        return;
      } */

      if (this.keyword.trim().length > 0) {
        uNavigateTo("/pages/goods/search?kw=" + this.keyword);
      } else uToast("请输入关键字~", "error");
    },
    onABC() {
      uRedirectTo("/pages/tab_bar/cart");
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./scss/index.scss";
.product-section {
  margin-top: 18px;
  flex: 1;
  height: calc(100vh-46px);
  .wrapper {
    padding: 0 20rpx;
    padding-bottom: 130rpx;
  }

  .ads1,
  .ads2 {
    height: 300rpx;
  }
  .ads1 {
    margin-bottom: 20rpx;
  }

  .category-name {
    padding: 30rpx 0;
    font-size: 26rpx;
    color: #777;
  }

  .products {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 20rpx;
  }

  .product {
    width: 47.5%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
    border-radius: 8px;
    position: relative;
    background-color: #fff;
    padding: 5px 0;
    .mask {
      width: 540rpx;
      height: 200rpx;
      background: rgba(17, 17, 17, 0.8);
      position: absolute;
      top: 0;
      left: 0;
      z-index: 9;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .image {
      width: 300rpx;
      height: 300rpx;
      margin-right: 10rpx;
      flex-shrink: 0;
    }

    .content {
      /*      display: flex;
      flex-direction: column;
      justify-content: space-between;
      height: 200rpx;
      flex: 1; */

      padding-left: 20px;
      .name {
        font-size: 14px;
        width: 360rpx;
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
        -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
        -webkit-line-clamp: 2; /** 显示的行数 **/
        overflow: hidden; /** 隐藏超出的内容 **/
      }

      .labels {
        display: flex;
        font-size: 20rpx;
        margin-bottom: 8rpx;
        overflow: hidden;
        flex-wrap: wrap;
        .label {
          max-width: 40%;
          padding: 6rpx 10rpx;
          margin-right: 10rpx;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }

      .description {
        margin-bottom: 20rpx;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        color: #777;
        font-size: 24rpx;
      }

      .price {
        color: #777;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .symbol {
          font-size: 18px;
          font-weight: bold;
          color: #ec3e40;
        }
      }
    }
  }
}
</style>
